package com.example.idachuappone.index;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.location.BDGeofence;
import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.location.LocationClientOption.LocationMode;
import com.example.idachuappone.LoadingActivity;
import com.example.idachuappone.R;
import com.example.idachuappone.cook.action.CookAction;
import com.example.idachuappone.cook.entity.Set;
import com.example.idachuappone.cook.item.PrompTwoCookActivity;
import com.example.idachuappone.index.action.IndexTwoAction;
import com.example.idachuappone.index.adapter.ImgAdapter;
import com.example.idachuappone.index.dao.impl.WelcomeDaoImpl;
import com.example.idachuappone.index.dialog.IDialog;
import com.example.idachuappone.index.dto.WelcomeDto;
import com.example.idachuappone.index.item.SearchCityActivity;
import com.example.idachuappone.index.ui.MyGallery;
import com.example.idachuappone.index.ui.MyGridView;
import com.example.idachuappone.index.welcomentity.Hot;
import com.example.idachuappone.index.welcomentity.InitData;
import com.example.idachuappone.index.welcomentity.Welcome;
import com.example.idachuappone.promptly.entity.UserInfo;
import com.example.idachuappone.utils.AppShareData;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.example.idachuappone.utils.CheckUtil;
import com.example.idachuappone.utils.ComUtil;
import com.example.idachuappone.utils.Constant;
import com.example.idachuappone.utils.FileUtil;
import com.example.idachuappone.utils.MainToast;
import com.example.idachuappone.utils.NetUtil;
import com.example.idachuappone.utils.PrefUtil;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapGlobalConfig.BitmapCacheManagementTask;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;

public class IndexFragTwo extends Fragment implements OnClickListener, OnItemClickListener {
	private Button btn_phone;
	private BitmapUtils bu;
	private String cityname;
	private String citynameDingwei;
	private Dialog dialogLoading;
	private MyGallery gallery;
	private boolean hasTopInfo;
	private ArrayList<String> imgList;
	private ImageView img_address_jian;
	private ImageView img_frist_icon;
	private ImageView img_tags_icon_0;
	private ImageView img_tags_icon_1;
	private ImageView img_tags_icon_2;
	private ImageView img_tags_icon_3;
	private boolean isfirst;
	private LinearLayout ll_tags_0;
	private LinearLayout ll_tags_1;
	private LinearLayout ll_tags_2;
	private LinearLayout ll_tags_3;
	private LinearLayout ll_top_dian;
	private double locLat;
	private double locLon;
	public LocationClient mLocationClient;
	private MGVAdapter mgvAdapter;
	private MyGridView mgv_main;
	public BDLocationListener myListener;
	private String paramCoordinate;
	private ArrayList<ImageView> portImg;
	private int preSelImgIndex;
	private RelativeLayout rl_first;
	private TextView tv_city_name;
	private TextView tv_first_description;
	private TextView tv_first_price;
	private TextView tv_first_title;
	private TextView tv_tags_title_0;
	private TextView tv_tags_title_1;
	private TextView tv_tags_title_2;
	private TextView tv_tags_title_3;
	private Welcome welcome;
	private WelcomeDto welcomeDto;

	private class MGVAdapter extends BaseAdapter {
		private Context context;
		private List<Hot> list;

		public MGVAdapter(Context context) {
			this.context = context;
		}

		public void setList(List<Hot> list) {
			this.list = list;
		}

		@Override
		public int getCount() {
			return this.list == null ? 0 : this.list.size();
		}

		@Override
		public Object getItem(int position) {
			return this.list == null ? null : (Hot) this.list.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = LinearLayout.inflate(this.context, R.layout.simple_index_mgv_item, null);
				holder.tv_hot_title = (TextView) convertView.findViewById(R.id.tv_hot_title);
				holder.tv_hot_description = (TextView) convertView.findViewById(R.id.tv_hot_description);
				holder.img_hot_icon = (ImageView) convertView.findViewById(R.id.img_hot_icon);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			Hot hot = this.list.get(position);
			holder.tv_hot_title.setText(hot.getTitle());
			holder.tv_hot_description.setText(hot.getDescription());
			IndexFragTwo.this.bu.display(holder.img_hot_icon, hot.getImg());
			return convertView;
		}
	}

	private class ViewHolder {
		ImageView img_hot_icon;
		TextView tv_hot_description;
		TextView tv_hot_title;

		private ViewHolder() {
		}
	}

	public class MyLocationListener implements BDLocationListener {
		@Override
		public void onReceiveLocation(BDLocation location) {
			IndexFragTwo.this.mLocationClient.stop();
			if (location == null) {
				IndexFragTwo.this.dialogLoading.dismiss();
				IndexFragTwo.this.cityname = "\u5317\u4eac";
				IndexFragTwo.this.getIndexData();
				IndexFragTwo.this.citynameDingwei = "\u65e0\u6cd5\u5b9a\u4f4d\u5f53\u524d\u57ce\u5e02";
				Intent intentCity = new Intent(IndexFragTwo.this.getActivity(), SearchCityActivity.class);
				intentCity.putExtra("cityname", IndexFragTwo.this.cityname);
				intentCity.putExtra("citynameDingwei", IndexFragTwo.this.citynameDingwei);
				IndexFragTwo.this.startActivity(intentCity);
				return;
			}
			Log.e("aaaaa", new StringBuilder(String.valueOf(location.getLocType())).toString());
			if (location.getLocType() == 61 || location.getLocType() == 161) {
				IndexFragTwo.this.locLat = location.getLatitude();
				IndexFragTwo.this.locLon = location.getLongitude();
				PrefUtil.getInstance(IndexFragTwo.this.getActivity()).setLocateTime(System.currentTimeMillis());
				IndexFragTwo.this.paramCoordinate = new StringBuilder(String.valueOf(String
						.valueOf(IndexFragTwo.this.locLon))).append(",")
						.append(String.valueOf(IndexFragTwo.this.locLat)).toString();
				Log.e("aaaa", IndexFragTwo.this.paramCoordinate);
				PrefUtil.getInstance(IndexFragTwo.this.getActivity()).setLocateCoor(IndexFragTwo.this.paramCoordinate);
				IndexFragTwo.this.cityname = location.getCity();
				IndexFragTwo.this.cityname = IndexFragTwo.this.cityname.replace("\u5e02", "");
				IndexFragTwo.this.citynameDingwei = IndexFragTwo.this.cityname;
				IndexFragTwo.this.setCityid();
				return;
			}
			IndexFragTwo.this.dialogLoading.dismiss();
			IndexFragTwo.this.cityname = "\u5317\u4eac";
			IndexFragTwo.this.getIndexData();
			IndexFragTwo.this.citynameDingwei = "\u65e0\u6cd5\u5b9a\u4f4d\u5f53\u524d\u57ce\u5e02";
			Intent intentCity = new Intent(IndexFragTwo.this.getActivity(), SearchCityActivity.class);
			intentCity.putExtra("cityname", IndexFragTwo.this.cityname);
			intentCity.putExtra("citynameDingwei", IndexFragTwo.this.citynameDingwei);
			IndexFragTwo.this.startActivity(intentCity);
		}
	}

	public IndexFragTwo() {
		this.preSelImgIndex = 0;
		this.mLocationClient = null;
		this.myListener = new MyLocationListener();
		this.hasTopInfo = false;
		this.isfirst = true;
		this.cityname = "\u5317\u4eac";
		this.citynameDingwei = "\u65e0\u6cd5\u5b9a\u4f4d\u5f53\u524d\u57ce\u5e02";
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.dialogLoading = ComUtil.createCusProgressSmallBlackBgDialog(getActivity());
		this.bu = BitmapUtilHelper.createBitmapUtil(getActivity());
		this.welcome = new Welcome();
		this.welcomeDto = new WelcomeDto();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.index_two, null);
		initView(view);
		checkNet();
		return view;
	}

	private void checkNet() {
		if (CheckUtil.checkNet(getActivity())) {
			this.dialogLoading.show();
			initLocation();
			return;
		}
		InitData initData = initdataCache();
		if (initData != null) {
			initData(NetUtil.unescapeUnicode(initData.getInit()));
		} else {
			initData(NetUtil.unescapeUnicode(FileUtil.getString(getResources().openRawResource(R.raw.initmaindata))));
		}
		this.isfirst = false;
	}

	private void initLocation() {
		this.mLocationClient = new LocationClient(getActivity().getApplicationContext());
		this.mLocationClient.registerLocationListener(this.myListener);
		this.mLocationClient.setLocOption(setOptionMap());
		this.mLocationClient.start();
	}

	private LocationClientOption setOptionMap() {
		LocationClientOption option = new LocationClientOption();
		option.setLocationMode(LocationMode.Hight_Accuracy);
		option.setCoorType(BDGeofence.COORD_TYPE_BD09LL);
		option.setScanSpan(LocationClientOption.MIN_SCAN_SPAN);
		option.setIsNeedAddress(true);
		option.setAddrType("all");
		return option;
	}

	private void getIndexData() {
		NetUtil.get(getActivity(), Constant.PACKAGES, 100, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				IndexFragTwo.this.dialogLoading.dismiss();
				IndexFragTwo.this.hasTopInfo = true;
				IndexFragTwo.this.isfirst = false;
				String json = responseInfo.result;
				IndexFragTwo.this.setDataCache(json);
				IndexFragTwo.this.initData(NetUtil.unescapeUnicode(json));
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				IndexFragTwo.this.dialogLoading.dismiss();
				InitData initData = IndexFragTwo.this.initdataCache();
				if (initData != null) {
					IndexFragTwo.this.initData(NetUtil.unescapeUnicode(initData.getInit()));
				} else {
					IndexFragTwo.this.initData(NetUtil.unescapeUnicode(FileUtil.getString(IndexFragTwo.this
							.getResources().openRawResource(R.raw.initmaindata))));
				}
				IndexFragTwo.this.isfirst = false;
			}
		});
	}

	private void setDataCache(String data) {
		if (initdataCache() != null) {
			new WelcomeDaoImpl(getActivity()).update(new InitData("maindata", data));
		} else {
			new WelcomeDaoImpl(getActivity()).add(new InitData("maindata", data));
		}
	}

	private InitData initdataCache() {
		return new WelcomeDaoImpl(getActivity()).selectByName("maindata");
	}

	@Override
	public void onResume() {
		super.onResume();
		if (!(this.hasTopInfo || this.isfirst)) {
			getIndexData();
		}
		if (AppShareData.isRefreshCityIndex) {
			this.cityname = AppShareData.cityName;
			getIndexData();
			initDefaultAddress();
			AppShareData.isRefreshCityIndex = false;
		}
	}

	public void initDefaultAddress() {
		NetUtil.get(getActivity(), Constant.USER_INFO, 100, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
					if (jsonObject.getInt("code") == 10000) {
						UserInfo userInfo = new UserInfo();
						userInfo.parseJson(jsonObject.getJSONObject("data"));
						PrefUtil prefUtil;
						if (userInfo.getAddresses() == null || userInfo.getAddresses().size() <= 0) {
							prefUtil = PrefUtil.getInstance(IndexFragTwo.this.getActivity());
							prefUtil.setFimallyLocateCoor(null);
							prefUtil.setArea(null);
							prefUtil.setXiaoQu(null);
							prefUtil.setDoor(null);
							prefUtil.setUserAddressId(null);
							return;
						}
						prefUtil = PrefUtil.getInstance(IndexFragTwo.this.getActivity());
						prefUtil.setFimallyLocateCoor(new StringBuilder(String.valueOf(userInfo.getAddresses().get(0)
								.getLng())).append(",").append(userInfo.getAddresses().get(0).getLat()).toString());
						prefUtil.setArea(userInfo.getAddresses().get(0).getArea());
						prefUtil.setXiaoQu(userInfo.getAddresses().get(0).getCommunity());
						prefUtil.setDoor(userInfo.getAddresses().get(0).getDoor_number());
						prefUtil.setName(userInfo.getAddresses().get(0).getName());
						prefUtil.setUserAddressId(userInfo.getAddresses().get(0).getId());
						prefUtil.setPhone(userInfo.getAddresses().get(0).getPhone());
					} else if (jsonObject.getInt("code") == 300) {
						MainToast.show(IndexFragTwo.this.getActivity(), jsonObject.getString("error"), 0);
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
			}
		});
	}

	private void initData(String json) {
		try {
			this.welcome = this.welcomeDto.getWelcome(getActivity(), json);
			LoadingActivity.welcome = this.welcome;
			setViewData();
		} catch (Exception e) {
			MainToast.show(getActivity(), e.getMessage(), 0);
		}
	}

	private void setViewData() {
		this.tv_city_name.setText(this.cityname);
		if (this.welcome.getFirst() != null) {
			this.tv_first_title.setText(this.welcome.getFirst().getTitle());
			this.tv_first_description.setText(this.welcome.getFirst().getDescription());
			this.tv_first_price.setText(this.welcome.getFirst().getPrice());
			this.img_frist_icon.setImageResource(getImgId(this.welcome.getFirst().getIcon()));
			if (this.welcome.getTags() != null && this.welcome.getTags().size() == 4) {
				this.tv_tags_title_0.setText(this.welcome.getTags().get(0).getTitle());
				if (this.welcome.getTags().get(0).getIcon().startsWith("http")) {
					this.bu.display(this.img_tags_icon_0, this.welcome.getTags().get(0).getIcon());
				} else {
					this.img_tags_icon_0.setImageResource(getImgId(this.welcome.getTags().get(0).getIcon()));
				}
				this.tv_tags_title_1.setText(this.welcome.getTags().get(1).getTitle());
				if (this.welcome.getTags().get(1).getIcon().startsWith("http")) {
					this.bu.display(this.img_tags_icon_1, this.welcome.getTags().get(1).getIcon());
				} else {
					this.img_tags_icon_1.setImageResource(getImgId(this.welcome.getTags().get(1).getIcon()));
				}
				this.tv_tags_title_2.setText(this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_FLUSH)
						.getTitle());
				if (this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_FLUSH).getIcon().startsWith("http")) {
					this.bu.display(this.img_tags_icon_2,
							this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_FLUSH).getIcon());
				} else {
					this.img_tags_icon_2.setImageResource(getImgId(this.welcome.getTags()
							.get(BitmapCacheManagementTask.MESSAGE_FLUSH).getIcon()));
				}
				this.tv_tags_title_3.setText(this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_CLOSE)
						.getTitle());
				if (this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_CLOSE).getIcon().startsWith("http")) {
					this.bu.display(this.img_tags_icon_3,
							this.welcome.getTags().get(BitmapCacheManagementTask.MESSAGE_CLOSE).getIcon());
				} else {
					this.img_tags_icon_3.setImageResource(getImgId(this.welcome.getTags()
							.get(BitmapCacheManagementTask.MESSAGE_CLOSE).getIcon()));
				}
			}
			initAdapter();
			initTopData();
			initCirclePoint();
		}
	}

	private void initView(View view) {
		this.mgv_main = (MyGridView) view.findViewById(R.id.mgv_main);
		this.mgv_main.setFocusable(false);
		this.mgvAdapter = new MGVAdapter(getActivity());
		this.mgv_main.setAdapter(this.mgvAdapter);
		this.mgv_main.setOnItemClickListener(this);
		this.tv_city_name = (TextView) view.findViewById(R.id.tv_city_name);
		this.tv_city_name.setOnClickListener(this);
		this.img_address_jian = (ImageView) view.findViewById(R.id.img_address_jian);
		this.img_address_jian.setOnClickListener(this);
		this.btn_phone = (Button) view.findViewById(R.id.btn_phone);
		this.btn_phone.setOnClickListener(this);
		this.rl_first = (RelativeLayout) view.findViewById(R.id.rl_first);
		this.rl_first.setOnClickListener(this);
		this.tv_first_title = (TextView) view.findViewById(R.id.tv_first_title);
		this.tv_first_description = (TextView) view.findViewById(R.id.tv_first_description);
		this.tv_first_price = (TextView) view.findViewById(R.id.tv_first_price);
		this.img_frist_icon = (ImageView) view.findViewById(R.id.img_first_icon);
		this.ll_tags_0 = (LinearLayout) view.findViewById(R.id.ll_tags_0);
		this.ll_tags_0.setOnClickListener(this);
		this.tv_tags_title_0 = (TextView) view.findViewById(R.id.tv_tags_title_0);
		this.img_tags_icon_0 = (ImageView) view.findViewById(R.id.img_tags_icon_0);
		this.ll_tags_1 = (LinearLayout) view.findViewById(R.id.ll_tags_1);
		this.ll_tags_1.setOnClickListener(this);
		this.tv_tags_title_1 = (TextView) view.findViewById(R.id.tv_tags_title_1);
		this.img_tags_icon_1 = (ImageView) view.findViewById(R.id.img_tags_icon_1);
		this.ll_tags_2 = (LinearLayout) view.findViewById(R.id.ll_tags_2);
		this.ll_tags_2.setOnClickListener(this);
		this.tv_tags_title_2 = (TextView) view.findViewById(R.id.tv_tags_title_2);
		this.img_tags_icon_2 = (ImageView) view.findViewById(R.id.img_tags_icon_2);
		this.ll_tags_3 = (LinearLayout) view.findViewById(R.id.ll_tags_3);
		this.ll_tags_3.setOnClickListener(this);
		this.tv_tags_title_3 = (TextView) view.findViewById(R.id.tv_tags_title_3);
		this.img_tags_icon_3 = (ImageView) view.findViewById(R.id.img_tags_icon_3);
		this.ll_top_dian = (LinearLayout) view.findViewById(R.id.ll_top_dian);
		this.gallery = (MyGallery) view.findViewById(R.id.gallery);
	}

	@Override
	public void onItemClick(AdapterView<?> adapterView, View arg1, int position, long id) {
		new IndexTwoAction().activityGoHot(getActivity(), this.welcome.getHot().get(position));
	}

	private void initTopData() {
		if (this.welcome.getTop() != null && this.welcome.getTop().size() != 0) {
			this.imgList = new ArrayList();
			for (int i = 0; i < this.welcome.getTop().size(); i++) {
				this.imgList.add(this.welcome.getTop().get(i).getImg());
			}
			this.preSelImgIndex = 0;
			this.gallery.setAdapter(new ImgAdapter(getActivity(), this.imgList));
			this.gallery.setFocusable(true);
			this.gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
				@Override
				public void onItemSelected(AdapterView<?> adapterView, View arg1, int selIndex, long arg3) {
					selIndex %= IndexFragTwo.this.imgList.size();
					IndexFragTwo.this.portImg.get(IndexFragTwo.this.preSelImgIndex).setImageResource(
							R.drawable.icon_slide);
					IndexFragTwo.this.portImg.get(selIndex).setImageResource(R.drawable.icon_slide_p);
					IndexFragTwo.this.preSelImgIndex = selIndex;
				}

				@Override
				public void onNothingSelected(AdapterView<?> adapterView) {
				}
			});
			this.gallery.setOnItemClickListener(new OnItemClickListener() {
				@Override
				public void onItemClick(AdapterView<?> adapterView, View arg1, int arg2, long arg3) {
					new IndexTwoAction().activityGoTop(IndexFragTwo.this.getActivity(), IndexFragTwo.this.welcome
							.getTop().get(IndexFragTwo.this.preSelImgIndex));
				}
			});
		}
	}

	private void initCirclePoint() {
		this.ll_top_dian.removeAllViews();
		if (this.imgList != null && this.imgList.size() > 0) {
			this.portImg = new ArrayList();
			for (int i = 0; i < this.imgList.size(); i++) {
				ImageView localImageView = new ImageView(getActivity());
				localImageView.setId(i);
				localImageView.setScaleType(ScaleType.FIT_XY);
				localImageView.setLayoutParams(new LayoutParams(24, 24));
				localImageView.setPadding(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY,
						BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY, BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY,
						BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY);
				localImageView.setImageResource(R.drawable.icon_slide);
				this.portImg.add(localImageView);
				this.ll_top_dian.addView(localImageView);
			}
		}
	}

	private void initAdapter() {
		this.mgvAdapter.setList(this.welcome.getHot());
		this.mgvAdapter.notifyDataSetChanged();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_phone /* 2131165312 */:
			new IDialog().showPhone(getActivity()).show();
		case R.id.tv_city_name /* 2131165405 */:
		case R.id.img_address_jian /* 2131165458 */:
			Intent intentCity = new Intent(getActivity(), SearchCityActivity.class);
			intentCity.putExtra("cityname", this.cityname);
			intentCity.putExtra("citynameDingwei", this.citynameDingwei);
			startActivity(intentCity);
		case R.id.rl_first /* 2131165461 */:
			startActivity(new Intent(getActivity(), PrompTwoCookActivity.class));
		case R.id.ll_tags_0 /* 2131165466 */:
			if (this.welcome.getTags() != null && this.welcome.getTags().size() > 0) {
				tagsClick(0);
			}
		case R.id.ll_tags_1 /* 2131165469 */:
			if (this.welcome.getTags() != null && this.welcome.getTags().size() > 0) {
				tagsClick(1);
			}
		case R.id.ll_tags_2 /* 2131165472 */:
			if (this.welcome.getTags() != null && this.welcome.getTags().size() > 0) {
				tagsClick(BitmapCacheManagementTask.MESSAGE_FLUSH);
			}
		case R.id.ll_tags_3 /* 2131165475 */:
			if (this.welcome.getTags() != null && this.welcome.getTags().size() > 0) {
				tagsClick(BitmapCacheManagementTask.MESSAGE_CLOSE);
			}
		default:
		}
	}

	private void tagsClick(int index) {
		new IndexTwoAction().activityGoTags(getActivity(), this.welcome.getTags().get(index));
	}

	public void showNoAddressService() {
		Builder dialog = new Builder(getActivity());
		dialog.setMessage("\u4eb2\u7231\u7684\u7528\u6237\uff0c\u60a8\u6240\u5728\u7684\u57ce\u5e02\u8fd8\u672a\u5f00\u901a\u7231\u5927\u53a8\u670d\u52a1\uff0c\u7231\u5927\u53a8\u6b63\u5728\u5feb\u9a6c\u52a0\u97ad\u5f00\u542f\u4e2d\uff0c\u656c\u8bf7\u5173\u6ce8");
		dialog.setPositiveButton("\u786e\u5b9a", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				PrefUtil.getInstance(IndexFragTwo.this.getActivity()).setIsAddressIndexDialog(false);
			}
		}).create();
		dialog.show();
	}

	private void setCityid() {
		NetUtil.get(getActivity(), Constant.SETS, 100, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				try {
					JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
					if (jsonObject.getInt("code") == 10000) {
						Set set = new Set();
						set.parseJson(jsonObject.getJSONObject("data"));
						int index = new CookAction().getCityIndex(IndexFragTwo.this.cityname, set.getCity());
						AppShareData.cityIndex = index;
						AppShareData.city_id = set.getCity().get(index).getId();
						AppShareData.cityName = set.getCity().get(index).getName();
						IndexFragTwo.this.getIndexData();
						if (index == 0 && !IndexFragTwo.this.citynameDingwei.equals("\u5317\u4eac")
								&& PrefUtil.getInstance(IndexFragTwo.this.getActivity()).getIsAddressIndexDialog()) {
							IndexFragTwo.this.showNoAddressService();
							return;
						}
						return;
					}
					MainToast.show(IndexFragTwo.this.getActivity(), jsonObject.getString("error"), 0);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
			}
		});
	}

	private int getImgId(String name) {
		return getResources().getIdentifier(name, "drawable", getActivity().getApplicationInfo().packageName);
	}
}
